<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author juwking
 */
abstract class TableControl {

    protected $user = 'root', $password, $dbase = 'wincon_mailing_db';
    protected $pdo;
    public static $emptyQuery;

    abstract function Select($param=null, $limit=null);

    abstract function Insert($param);

    abstract function Update($param);

    abstract function Delete($param);

    abstract function getEmptyRecord();

    function __construct() {
        $this->pdo = new PDO('mysql:host=localhost;dbname=' . $this->dbase . ';charset=UTF-8', $this->user, $this->password);
        $this->pdo->query('SET NAMES UTF8');
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }

    function initPDO() {
        $this->pdo = new PDO('mysql:host=localhost;dbname=' . $this->dbase, $this->user, $this->password);
        $this->pdo->query('SET NAMES UTF8');
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }

    function adaptKeys($recordArray) {
        $adaptedArray = array();
        foreach ($this->getColumns() as $key => $value) {
            $adaptedArray[':'. $value] = $recordArray[$value];
        }
        array_shift($adaptedArray);
        return $adaptedArray;
    }

    abstract public function getTableName();

    abstract public function getColumns();
}

?>
